package com.whfp.coky.ui.adpter

import android.content.Context
import android.graphics.drawable.Drawable
import com.whfp.coky.databinding.ItemFluorNavigationBinding
import com.whfp.coky.ui.base.BaseAdapter
import com.whfp.coky.utils.LogUtil

class NavigationAdapter constructor(context: Context) :
    BaseAdapter<ItemFluorNavigationBinding, NavigationAdapter.MenuItem>(context) {

    /** 当前选中条目位置 */
    internal var selectedPosition: Int = 0
        get() = field
        set(value) {
            field = value
            notifyDataSetChanged()
            LogUtil.e("我进了set方法》》》》。。")
        }

    /** 导航栏点击监听 */
    internal var listener: OnNavigationListener? = null
        get() = field
        set(value) {
            field = value
        }


    override fun convert(v: ItemFluorNavigationBinding, t: MenuItem, position: Int) {
        v.ivHomeNavigationIcon.setImageDrawable(t.getDrawable())
        v.tvHomeNavigationTitle.text = t.getText()
        v.ivHomeNavigationIcon.isSelected = (selectedPosition == position)
        v.tvHomeNavigationTitle.isSelected = (selectedPosition == position)
//            itemClick {
//                if (selectedPosition == it) {
//                    return@itemClick
//                }
//                if (listener == null) {
//                    selectedPosition = position
//                    notifyDataSetChanged()
//
//                }else if (listener!!.onNavigationItemSelected(position)) {
//                    selectedPosition = position
//                    notifyDataSetChanged()
//                }
//            }
    }


//    /**
//     * 设置导航栏监听
//     */
//    fun setOnNavigationListener(listener: OnNavigationListener?) {
//        this.listener = listener
//    }


    class MenuItem constructor(private val text: String?, private val drawable: Drawable?) {

        fun getText(): String? {
            return text
        }

        fun getDrawable(): Drawable? {
            return drawable
        }
    }

    interface OnNavigationListener {
        fun onNavigationItemSelected(position: Int): Boolean
    }

}